package com.dd.controller;

import com.dd.comm.R;
import com.dd.entity.Squad;
import com.dd.service.ISquadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dhd
 * @since 2024-12-12 08:58
 */
@RestController
@RequestMapping("/squad")
@Tag(name = "SquadController", description = "小组管理")
@CrossOrigin
public class SquadController {
    @Autowired
    ISquadService squadService;

    //获取小组列表
    @GetMapping
    @Operation(summary = "获取小组接口", description = "获取小组列表")
    public R<List<Squad>> getList(){
        List<Squad> list = squadService.list();
        return R.success(list);
    }

    //新增小组
    @PostMapping
    @Operation(summary = "新增小组接口", description = "新增小组")
    public R<String> addSquad(@RequestBody Squad squad){
        squadService.save(squad);
        return R.success();
    }

    //修改小组
    @PutMapping
    @Operation(summary = "修改小组接口", description = "修改小组")
    public R<String> updateSquad(@RequestBody Squad squad){
        squadService.updateById(squad);
        return R.success();
    }

    //删除小组
    @DeleteMapping("/{id}")
    @Operation(summary = "删除小组接口", description = "删除小组")
    public R delSquad(@PathVariable("id") Integer SquadId){
        squadService.delSquad(SquadId);
        return R.success();
    }
}
